package com.itheima.array;

import java.util.Scanner;

public class learn1 {
    public static void main(String[] args) {
        randomCall();
    }

    public static void randomCall(){
        // 定义一个数组来存储8名学生的成绩
        double[] scores = new double[8];
        Scanner scanner = new Scanner(System.in);

        // 输入8名学生的成绩
        System.out.println("请输入8名学生的Java成绩：");
        for (int i = 0; i < scores.length; i++) {
            System.out.print("学生" + (i + 1) + "的成绩: ");
            scores[i] = scanner.nextDouble();
        }

        // 计算平均分、最高分和最低分
        double sum = 0;
        double maxScore = scores[0];
        double minScore = scores[0];

        for (double score : scores) {
            sum += score;
            if (score > maxScore) {
                maxScore = score;
            }
            if (score < minScore) {
                minScore = score;
            }
        }

        double averageScore = sum / scores.length;

        // 输出结果
        System.out.println("平均分: " + averageScore);
        System.out.println("最高分: " + maxScore);
        System.out.println("最低分: " + minScore);

        // 关闭scanner
        scanner.close();
    }
}
